package top.wardyan.wtask.ctrl;

import java.sql.Timestamp;
import java.util.List;

import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Record;

import top.wardyan.base.common.util.DateUtil;
import top.wardyan.common.ctrl.BaseController;
import top.wardyan.wtask.feishu.api.FeishuMsgBusiness;
import top.wardyan.wtask.jobs.FeishuCheckJob;
import top.wardyan.wtask.service.IProcService;
import top.wardyan.wtask.tapd.api.TapdBusiness;

@Path("/taskcount")
public class TaskCountCtrl extends BaseController{

	private static final cn.hutool.log.Log log = cn.hutool.log.Log.get();

	@Inject FeishuMsgBusiness feishuBusiness;
	@Inject TapdBusiness tapdBusiness;
	@Inject IProcService procService;
	@Inject FeishuCheckJob checkJob;
	
	
	
	public void home(
			Timestamp begin, Timestamp end
			, String man, String cust, String status, String text,Boolean isCust
			, Boolean status1, Boolean status2, Boolean status3
			, Integer pageNo
			) {
		
		// 如果日期没有赋值,就自动过去一个月
		if(begin == null) {
			begin = DateUtil.range(15);
		}
		if(end == null) {
			end = DateUtil.getCurrentTimestamp();
		}
		end = DateUtil.range(end, 2);
		
		List<Record> tasks = procService.yp_query_task(begin, end, man, text, cust, status);
		
		
		List<Record> counts = procService.yp_query_task_count(begin, end, man, text, cust, status, isCust);
		this.set("taskdatas", tasks);
		this.set("countdatas", counts);

		this.set("man", man);
		this.set("cust", cust);
		this.set("status", status);
		this.set("text", text);
		this.set("isCust", isCust);

		
		if(status1 != null && status1) {
			List<Record> taskdata1 = procService.yp_query_task(begin, end, man, text, cust, "未开始");
			this.set("taskdata1", taskdata1);
		}
		if(status2 != null && status2) {
			List<Record> taskdata2 = procService.yp_query_task(begin, end, man, text, cust, "已完成");
			this.set("taskdata2", taskdata2);
		}

		if(status3 != null && status3) {
			List<Record> taskdata3 = procService.yp_query_task(begin, end, man, text, cust, "进行中");
			this.set("taskdata3", taskdata3);
		}

		this.set("status1", status1);
		this.set("status2", status2);
		this.set("status3", status3);
		this.set("begin", begin);
		this.set("end", end);
		
		

		List<Record> tops = procService.yp_query_task_max(begin, end, man, text, cust, status);
		this.set("tops", tops);
		
		this.renderTemplate("task.html");
	}
}
